<!DOCTYPE html>
<html>
<head>
    <title>代理测试页面</title>
    <meta charset="utf-8">
</head>
<body>
    <h1>代理测试</h1>
    
    <div>
        <textarea id="dreamContent" placeholder="请输入梦境内容" rows="4" cols="50">梦见蛇</textarea>
        <br><br>
        <button id="testBtn">测试解梦API</button>
    </div>
    
    <div id="result" style="margin-top: 20px; padding: 10px; border: 1px solid #ccc;">
        <h3>测试结果:</h3>
        <pre id="resultContent">点击按钮开始测试</pre>
    </div>

    <script>
        document.getElementById('testBtn').addEventListener('click', async function() {
            const dreamContent = document.getElementById('dreamContent').value;
            const resultDiv = document.getElementById('resultContent');
            const btn = document.getElementById('testBtn');
            
            if (!dreamContent.trim()) {
                resultDiv.textContent = '请输入梦境内容';
                return;
            }
            
            try {
                btn.disabled = true;
                btn.textContent = '测试中...';
                resultDiv.textContent = '正在请求...';
                
                const response = await fetch('/api/dreams/interpret', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ dreamContent: dreamContent })
                });
                
                const data = await response.json();
                
                if (response.ok) {
                    resultDiv.innerHTML = `<div class="result success">✅ 解梦成功\n${JSON.stringify(data, null, 2)}</div>`;
                } else {
                    resultDiv.innerHTML = `<div class="result error">❌ 解梦失败: ${data.message || response.statusText}</div>`;
                }
            } catch (error) {
                resultDiv.innerHTML = `<div class="result error">❌ 请求失败: ${error.message}</div>`;
            } finally {
                btn.disabled = false;
                btn.textContent = '测试解梦API';
            }
        });
    </script>
</body>
</html>